from nodetypes.ntypes.Document.showBase.RDF import Transform, Document


class Document(Document):
    
    containsKey = 'mTranslations'
    
    def filterContainedNodes(self, context, consumer, nodes, driver, locale, nfilter=lambda n: True):
        # filter only nodes that have matching acl
        action = context.action
        acls = context.acls.checkNodeAcls
                
        model = context.model.rdf_clone(driver)
        mid = model.rdf_value
        
        # MAX DISPLAY LIMIT
        # if len(nodes) == max_display_limit:
        #   return
        # Should this be a user preference???
        key = self.containsKey
        
        # filter direct children nodes
        n_append = nodes.append        
        for np, n in model.rdf_toRelations(key):
            #n = n.rdf_clone(driver)
            if nfilter(n) and \
                acls(n.rdf_getDomain(), action):
                n_append(n)
                
                consumer((
                    n.rdf_asStatement(
                        np,
                        mid
                    ),
                ))
                
        return nodes
    

class Transform(Transform):
    
    newDocument = Document